﻿using System;
using ProjScan.Modules;
using ProjScan.Tools;
using UnityEditor;
using UnityEngine;

namespace ProjScan.RecordManager.AssetData
{
	// Token: 0x020002AB RID: 683
	internal class TextureAssetData : ImportAssetData<Texture, TextureImporter>
	{
		// Token: 0x060011C2 RID: 4546 RVA: 0x00053734 File Offset: 0x00051934
		public TextureAssetData(int directoryID, string assetPath, Texture texture, TextureImporter textureImporter) : base(directoryID, assetPath, texture, textureImporter)
		{
			this.textureColorArray = null;
			bool flag = textureImporter == null;
			if (flag)
			{
				this.noImporter = true;
			}
			else
			{
				this.sourceTextureHasAlpha = textureImporter.DoesSourceTextureHaveAlpha();
				this.filterMode = textureImporter.filterMode;
				this.isReadable = textureImporter.isReadable;
				this.textureImporterType = textureImporter.textureType;
				this.mipmapEnabled = textureImporter.mipmapEnabled;
				this.textureWrapMode = textureImporter.wrapMode;
				this.anisoLevel = textureImporter.anisoLevel;
			}
			object[] parameters = new object[]
			{
				texture
			};
			AssemblyTools.I.TryGetMethodResult<TextureFormat>("UnityEditor.TextureUtil", "GetTextureFormat", out this.textureFormat, parameters);
			this.width = texture.width;
			this.height = texture.height;
			Texture2D texture2D = texture as Texture2D;
			bool flag2 = texture2D != null;
			if (flag2)
			{
				this.isTexture2D = true;
				this.hasAlpha = this.HasAlphaTextureFormat(texture);
				try
				{
					this.textureColorArray = ToolsHelper.PixelArrayFromTexture2D(texture2D);
				}
				catch (Exception ex)
				{
					ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Basic_Assets_Check, "TextureRecord", string.Concat(new string[]
					{
						(ex.GetType() == null) ? null : ex.GetType().ToString(),
						"\n",
						ex.Message,
						"\n",
						ex.StackTrace
					}));
				}
			}
			else
			{
				this.isTexture2D = false;
			}
		}

		// Token: 0x060011C3 RID: 4547 RVA: 0x000538C8 File Offset: 0x00051AC8
		private bool HasAlphaTextureFormat(Texture texture)
		{
			bool result = false;
			object[] parameters = new object[]
			{
				this.textureFormat
			};
			AssemblyTools.I.TryGetMethodResult<bool>("UnityEditor.TextureUtil", "HasAlphaTextureFormat", out result, parameters);
			return result;
		}

		// Token: 0x060011C4 RID: 4548 RVA: 0x0005390C File Offset: 0x00051B0C
		private bool CheckForAlphaInColourArray(Color32[] colorArray, Texture2D texture2D)
		{
			int num = texture2D.width;
			int num2 = texture2D.height;
			bool result = true;
			for (int i = 0; i < num2; i++)
			{
				int num3 = i * num;
				bool flag = colorArray[num3].a > 0;
				if (flag)
				{
					result = false;
					break;
				}
			}
			return result;
		}

		// Token: 0x060011C5 RID: 4549 RVA: 0x00053968 File Offset: 0x00051B68
		public override string GetCSVHeader()
		{
			return "Name,DirID,Width,Height";
		}

		// Token: 0x060011C6 RID: 4550 RVA: 0x00053980 File Offset: 0x00051B80
		public override string GetInfo()
		{
			string[] values = new string[]
			{
				ToolsHelper.QuoteString(this.fileName),
				",",
				this.assetPathId.ToString(),
				",",
				this.width.ToString(),
				",",
				this.height.ToString()
			};
			return string.Concat(values);
		}

		// Token: 0x060011C7 RID: 4551 RVA: 0x0000879B File Offset: 0x0000699B
		public override void Reset()
		{
			this.asset = null;
			this.assetImporter = null;
			this.textureColorArray = null;
		}

		// Token: 0x04000A78 RID: 2680
		public static bool globalBool1;

		// Token: 0x04000A79 RID: 2681
		public static bool globalBool2;

		// Token: 0x04000A7A RID: 2682
		public static bool globalBool3;

		// Token: 0x04000A7B RID: 2683
		public int width;

		// Token: 0x04000A7C RID: 2684
		public int height;

		// Token: 0x04000A7D RID: 2685
		public bool isTexture2D;

		// Token: 0x04000A7E RID: 2686
		public bool hasAlpha;

		// Token: 0x04000A7F RID: 2687
		public TextureFormat textureFormat;

		// Token: 0x04000A80 RID: 2688
		public bool sourceTextureHasAlpha;

		// Token: 0x04000A81 RID: 2689
		public FilterMode filterMode;

		// Token: 0x04000A82 RID: 2690
		public bool isReadable;

		// Token: 0x04000A83 RID: 2691
		public TextureImporterType textureImporterType;

		// Token: 0x04000A84 RID: 2692
		public bool mipmapEnabled;

		// Token: 0x04000A85 RID: 2693
		public TextureWrapMode textureWrapMode;

		// Token: 0x04000A86 RID: 2694
		public int anisoLevel;

		// Token: 0x04000A87 RID: 2695
		public Color32[] textureColorArray;

		// Token: 0x020002AC RID: 684
		public enum CommonlyUsedFormats
		{
			// Token: 0x04000A89 RID: 2697
			UnKnown,
			// Token: 0x04000A8A RID: 2698
			Alpha8,
			// Token: 0x04000A8B RID: 2699
			RGBA,
			// Token: 0x04000A8C RID: 2700
			RGB,
			// Token: 0x04000A8D RID: 2701
			DXT,
			// Token: 0x04000A8E RID: 2702
			BC,
			// Token: 0x04000A8F RID: 2703
			PVRTC,
			// Token: 0x04000A90 RID: 2704
			ETC,
			// Token: 0x04000A91 RID: 2705
			EAC,
			// Token: 0x04000A92 RID: 2706
			ETC2,
			// Token: 0x04000A93 RID: 2707
			ASTC
		}
	}
}
